
<div class="row">
    <div class="col-sm-2">
        <button type="button" onClick="upFiles_{{ $uEditorStatic }}()" class="btn btn-info">附件上传</button>
    </div>
    <div class="col-sm-10 file-list" id="file-list-{{ $uEditorStatic }}">
        @if($maxNumber == 1)
            <div class="col-sm-3 file-info">
                <a href="{{ get_value($inputValue, 'url', 'javascript:void(0)') }}" download="{{ get_value($inputValue, 'desc', '') }}" class="label label-info">{{ get_value($inputValue, 'desc', '暂无文件') }}</a>
                <input type="hidden" name="{{ $inputName }}[url]" id="upload-file-{{ $uEditorStatic }}-url" value="{{ get_value($inputValue, 'url', '') }}" title="附件地址">
                <input type="hidden" name="{{ $inputName }}[id]" id="upload-file-{{ $uEditorStatic }}-id" value="{{ get_value($inputValue, 'id', 0) }}" title="附件编号">
                <textarea class="form-control" name="{{ $inputName }}[desc]" id="upload-file-{{ $uEditorStatic }}-desc" title="附件描述">{{ get_value($inputValue, 'desc', '') }}</textarea>
            </div>
        @else
            @foreach($inputValue as $key=>$value)
                <div class="col-sm-3 file-info">
                    <a href="{{ get_value($inputValue, 'url', 'javascript:void(0)') }}" download="{{ get_value($value, 'desc', '') }}" class="label label-info">{{ get_value($inputValue, 'desc', '暂无文件') }}</a>
                    <input type="hidden" name="{{ $inputName }}[{{ $key }}][url]" value="{{ get_value($value, 'url', '') }}" title="附件地址">
                    <input type="hidden" name="{{ $inputName }}[{{ $key }}][id]" value="{{ get_value($value, 'id', 0) }}" title="附件编号">
                    <textarea class="form-control" name="{{ $inputName }}[{{ $key }}][desc]" title="附件描述" placeholder="请输入附件描述信息">{{ get_value($value, 'desc', '') }}</textarea>

                    <button type="button" class="btn btn-box-tool" onclick="removeFile(this)"><i class="fa fa-times"></i></button>
                </div>
            @endforeach

            <!--<div class="col-sm-3 file-info">
            <img class="img-responsive" src="{{ asset('img-lte/photo1.png') }}">
            <input type="hidden" name="{{ $inputName }}[0][url]" value="" title="附件地址">
            <input type="hidden" name="{{ $inputName }}[0][id]" value="" title="附件编号">
            <textarea class="form-control" name="{{ $inputName }}[0][desc]" title="附件描述" placeholder="请输入附件描述信息"></textarea>-->
        @endif
        <div style="clear: both;"></div>
    </div>
</div>

@if($static == 1)
<style>
    .file-list .file-info {height: 100px;}
    .file-list .btn-box-tool {position: absolute; top:0; right: 0;}
    .file-list .file-info textarea {resize:none;width: 90px;height: 32px;}
</style>
@endif

@if($uEditorStatic==1)
    <script type="text/javascript" charset="utf-8" src="{{ asset('plugins/ueditor/1.4.3/ueditor.config.js') }}"></script>

    <script type="text/javascript" charset="utf-8" src="{{ asset('plugins/ueditor/1.4.3/ueditor.all.js') }}"></script>

    <script type="text/javascript" src="{{ asset('plugins/ueditor/1.4.3/lang/zh-cn/zh-cn.js') }}"></script>



    <script>
        window.UEDITOR_HOME_URL = "{{ asset('plugins/ueditor/1.4.3') }}";

        window.UEDITOR_CONFIG.serverUrl = window.UEDITOR_HOME_URL;

        window.UEDITOR_CONFIG.serverUrl = "{{ url('api/uploads') }}";
    </script>
@endif
<script type="text/javascript" id="ueditor-upload-{{ $uEditorStatic }}"></script>

<script>
    var maxNumber_{{ $uEditorStatic }} = "{{ $maxNumber }}";
    var inputName_{{ $uEditorStatic }} = "{{ $inputName }}";

    //实例化编辑器
    var ueditorUpload_{{ $uEditorStatic }} = UE.getEditor('ueditor-upload-{{ $uEditorStatic }}', {
        autoHeightEnabled:false
    });
    ueditorUpload_{{ $uEditorStatic }}.ready(function ()
    {
        ueditorUpload_{{ $uEditorStatic }}.hide();//隐藏编辑器

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        ueditorUpload_{{ $uEditorStatic }}.addListener('afterUpfile', function (t, arg) {
            if (maxNumber_{{ $uEditorStatic }} == 1) {
                $("#upload-file-{{ $uEditorStatic }}-url").parent().children('a').attr('href', arg[0].url);
                $("#upload-file-{{ $uEditorStatic }}-url").parent().children('a').attr('download', arg[0].title);
                $("#upload-file-{{ $uEditorStatic }}-url").parent().children('a').text(arg[0].title);
                $("#upload-file-{{ $uEditorStatic }}-url").val(arg[0].url);
            } else {
                var html = '';
                var number = $("#file-list-{{ $uEditorStatic }} .file-info").length;
                $.each(arg, function (key, value) {
                    var n = number + key;
                    html += '<div class="col-sm-3 file-info">\n' +
                        '                <a href="'+value.url+'" download="'+value.title+'" class="label label-info">'+value.title+'</a>\n' +
                        '                <input type="hidden" name="'+inputName_{{ $uEditorStatic }}+'['+n+'][url]" value="'+value.url+'" title="文件地址">\n' +
                        '                <input type="hidden" name="'+inputName_{{ $uEditorStatic }}+'['+n+'][id]" value="0" title="文件编号">\n' +
                        '                <textarea class="form-control" name="'+inputName_{{ $uEditorStatic }}+'['+n+'][desc]" title="文件描述" placeholder="请输入描述信息">'+value.title+'</textarea>\n' +
                        '                <button type="button" class="btn btn-box-tool" onclick="removeFile(this)"><i class="fa fa-times"></i></button>\n' +
                        '</div>';
                });

                $("#file-list-{{ $uEditorStatic }}").append(html);

            }
        });
    });


    //弹出文件上传的对话框
    function upFiles_{{ $uEditorStatic }}() {
        var myFiles = ueditorUpload_{{ $uEditorStatic }}.getDialog("attachment");
        myFiles.open();
    }


    if(!removeFile || typeof(removeFile) != "function") {
        function removeFile(obj) {
            $(obj).parent().remove();
        }
    }
</script>